import React, {Component} from 'react'
import {ListComponent} from '../../../components'
import {ListBox} from '../../../components'
import { Form, Modal, Button } from 'antd';
// 入库过渡库位选择弹出框
export default class InstockTranLocModalTable extends Component {
    constructor(props) {
        super(props);
        this.state = {
            visible: false,
            rowObj: {},
        }
        this.selectRowObj = {};
        this.rowOperation = [
            {
                handleName: 'rowClick',
                showName: '行单击选择事件'
            }
        ];
        this.headerOperation = [];

       //table列表展示列配置
        //showName、columnName 必有属性， columnWidth 可选，默认100, columnHidden: true 列隐藏（用于列配置显示隐藏）, foreverHidden: true 列永久隐藏
        this.tableColumn = {
            data: [
                { showName: '库位编码',
                    columnName: 'locationCode'
                },{
                    showName: '库区编码',
                    columnName: 'areaCode'
                },{
                    showName: '区域编码',
                    columnName: 'regionCode'
                },{
                    showName: '仓库编码',
                    columnName: 'warehouseCode'
                },{
                    showName: '上架顺序',
                    columnName: 'shelfOrder'
                },{
                    showName: '盘点顺序',
                    columnName: 'checkOrder'
                },{
                    showName: '拣货顺序',
                    columnName: 'pickOrder'
                },{
                    showName: '库位使用',
                    columnName: 'locationUse'
                },{
                    showName: '是否允许拣货',
                    columnName: 'pickFlag',
                    columnWidth: 150,
                    showOption:[
                        {
                            optionKey:'',
                            optionShow:''
                        },{
                            optionKey:'0',
                            optionShow:'否'
                        },{
                            optionKey:'1',
                            optionShow:'是'
                        }
                    ]
                },{
                    showName: '库位类型',
                    columnName: 'locationType'
                },{
                    showName: '库位属性',
                    columnName: 'locationAttr'
                },{
                    showName: '周转需求',
                    columnName: 'turnDemand'
                },{
                    showName: '库存环境',
                    columnName: 'stockEnv'
                },{
                    showName: '校验码',
                    columnName: 'checkCode'
                },{
                    showName: '工作区',
                    columnName: 'workArea'
                },{
                    showName: '体积限制',
                    columnName: 'volumeLimit'
                },{
                    showName: '重量限制',
                    columnName: 'weightLimit'
                },{
                    showName: '箱数限制',
                    columnName: 'boxLimit'
                },{
                    showName: '数量限制',
                    columnName: 'qtyLimit'
                },{
                    showName: '托盘限制',
                    columnName: 'palletLimit'
                },{
                    showName: '长度',
                    columnName: 'length'
                },{
                    showName: '宽度',
                    columnName: 'width'
                },{
                    showName: '高度',
                    columnName: 'height'
                },{
                    showName: 'X坐标',
                    columnName: 'xcoordinate'
                },{
                    showName: 'Y坐标',
                    columnName: 'ycoordinate'
                },{
                    showName: 'Z坐标',
                    columnName: 'zcoordinate'
                },{
                    showName: '排',
                    columnName: 'locRow'
                },{
                    showName: '层数',
                    columnName: 'layerNum'
                },{
                    showName: '列',
                    columnName: 'locColumn'
                },{
                    showName: '巷道',
                    columnName: 'bord'
                },{
                    showName: '允许混放产品',
                    columnName: 'productMix',
                    columnWidth: 130
                },{
                    showName: '允许混放批次',
                    columnName: 'batchMix',
                    columnWidth: 130
                }
            ]
        };

        this.searchComponentData = [
            {
                showName: '是否允许拣货',
                name:'pickFlag',
                type: 'select',
                url: null,
                optionList:[
                    {
                        optionKey:'',
                        optionShow:''
                    },{
                        optionKey:'0',
                        optionShow:'否'
                    },{
                        optionKey:'1',
                        optionShow:'是'
                    }
                ]
            }
        ];
    }

    rowHandles = (strHandles, rowObj) => {
        if(strHandles == 'rowClick'){
            this.rowClickHandle(rowObj);
        }
    }

    rowClickHandle = (rowObj) => {    
        console.log('点击选中====',rowObj);    
        this.selectRowObj = rowObj[0].data;        
    }
    refreshHandle = () => {
        this.refs.listComponent.refreshHandle();
    }
    showModal = () => {
        this.setState({
            visible: true,
        });
    
        this.selectRowObj = {};
        // this.refreshHandle();
    }
    handleOk = () => {
        this.setState({
            visible: false
        })
        let resultData = {};
        resultData.value = this.selectRowObj.locationCode;
        resultData.type = 'instock';
        this.props.getTableData(resultData);
    }
    handleCancel = () => {
        this.setState({
            visible: false
        })
    }

    render() {
        //当左侧隐藏时，列表宽度加上左侧的宽度，
        //1、当前this.props.isHideLeft 是从页面组件containers/Main/main.js传过来
        //2、this.props.isHideLeft 最顶级赋值是在页面 containers/Main/main.js
        let isHideLeft = this.props.isHideLeft;

        return(
            <Modal
                    style={{top: '20px',maxHeight:'500px'}}
                    visible={this.state.visible}
                    title='入库过渡库位'
                    onOk={this.handleOk}
                    onCancel={this.handleCancel}
                    width={'1015px'}
                    footer={[
                        <Button key="back" onClick={this.handleCancel}>取消</Button>,
                        <Button key="submit" type="primary" onClick={this.handleOk}>
                        确定
                        </Button>,
                    ]}
                    maskClosable={false}
            >
                <ListBox
                    url = '/base/data/location/instock/list'
                    tableColumnData = {this.tableColumn}
                    rowHandles = {this.rowHandles}
                    rowOperation = {this.rowOperation}
                    ref = "listComponent"
                    searchComponentData={this.searchComponentData}
                    headerOperation = {this.headerOperation}
                    subtractHeight = '37'
                    subtractWidth ='145'
                    isRowSingle = "true"
                />
            </Modal>
        )
    }
}
